package com.woniuedu.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuedu.dao.CourseDao;
import com.woniuedu.dto.CommentDto;
import com.woniuedu.dto.CourseInfoDto;
import com.woniuedu.dto.CourseVideo;
import com.woniuedu.dto.FindCourseDto;
import com.woniuedu.entity.Comment;
import com.woniuedu.entity.Course;
import com.woniuedu.entity.ResponseEntity;
import com.woniuedu.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * author: 承雍
 * Date: 2022/4/19 10:47
 * Description:课程业务实现层
 */

@Service
public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements ICourseService {
    @Autowired(required = false)
    private CourseDao courseDao;

    @Override
    public IPage<Course> findAllCourse(Integer currentPage, Integer pageSize, FindCourseDto findCourseDto) {
        IPage<Course> iPage = new Page<>(currentPage, pageSize);
        return courseDao.findAllCourse(iPage,findCourseDto);
    }

    @Override
    public ResponseEntity<CourseInfoDto> findCourseInfo(String id) {
        CourseInfoDto courseInfoDto=courseDao.findCourseInfo(id);
        if (courseInfoDto != null){
            return new ResponseEntity<>(200,"查询成功",courseInfoDto);
        }else{
            return new ResponseEntity<>(500,"查询失败",null);
        }
    }

    @Override
    public List<CourseVideo> findCourseVideo(String id) {
        List<CourseVideo> courseVideo=courseDao.findCourseVideo(id);
        if (courseVideo.size()>0){
            return courseVideo;
        }else {
            return null;
        }
    }

    @Override
    public IPage<Comment> findAllComment(CommentDto commentDto) {
        IPage<Comment> page=new Page<>(commentDto.getCurrentPage(), commentDto.getPageSize());
        return courseDao.findAllComment(page,commentDto.getCommentCourseId());
    }

}
